﻿/**
 *  广告模块整合 20171023
 */
define(function(require,exports,module) {
    var myPub = require('./public');
    var adsModel = require('./adsModel');
    // var BASE_URL = '';

    module.exports = {
        init: function(data,names) {
            adsAjax.AdsAjaxData(data)
        }
    };

    var adsAjax = {
        // 设置广告数据
        AdsAjaxData: function (index, categoryNames, fn) {
            var _this = this;
            var advertUrl = BASE_URL +  "/moduleAdvert/getShowAdvert";
            var data = {"sceneName":"支付完成页"};
            // if(index != 0){
            //     data = {"sceneName":categoryNames[index-1]};
            // }

            G_JSON_POST(advertUrl,data,function (data) {
                if(data.length <= 0){
                    return;
                }
                for (var idx = 0; idx < data.length; idx ++ ){
                    var advertItem = data[idx];
                    var restrictions = advertItem.restrictions;
                    if (restrictions == null){

                    }else {
                        if (restrictions == 0){
                            var tflag = true;
                            var goodsIds = advertItem.goodsId;
                            for(var i=0;i<goodsSnList.length;i++){
                                for(var j=0;j<goodsIds.length;j++){

                                    if (goodsSnList[i] == goodsIds[j]){
                                        tflag = false;
                                        break;
                                    }
                                }
                                if (!tflag){
                                    break;
                                }
                            }
                            if (tflag){
                                continue;
                            }
                        } else if (restrictions != newUser){
                            continue;
                        }
                    }
                    switch (advertItem.moduleType) {
                        case "NAVIGATION" :
                            adsModel.adsHtml.AdsHorizontal(advertItem, index);
                            break;
                        case "NAVIGATION_MIN" :
                            adsModel.adsHtml.AdsHorizontalMin(advertItem, index);
                            break;
                        case "SHOPWINDOW" :
                            adsModel.adsHtml.AdsGroup3(advertItem, index);
                            break;
                        case "GOODSSCROLL" :
                            adsModel.adsHtml.GoodsHScroll(advertItem, index);
                            break;
                        case "SINGLEGOODS" :
                            adsModel.adsHtml.AdsBanner(advertItem, index);
                            break;
                        case "DOUBLEGOODS" :
                            adsModel.adsHtml.AdsGroup2(advertItem, index);
                            break;
                        case "GOODSGROUP" :
                            adsModel.adsHtml.AdsAndScroll(advertItem, index);
                            break;
                        case "HEADLINE" :
                            adsModel.adsHtml.AdsHeadline(advertItem, index);
                            break;
                        case "ONEFOURADVERT" :
                            adsModel.adsHtml.AdsOneFour(advertItem, index);
                            break;
                        case "BANNER_TYPE_1" :
                            adsModel.adsHtml.AdsGoodsBanner(advertItem, index);
                            break;
                        case "BANNER_TYPE_2" :
                            adsModel.adsHtml.AdsPicBanner(advertItem, index);
                            break;
                        default:
                            console.error("暂不支持的广告类型 " + advertItem.moduleType);
                            break
                    }
                }

                if(fn)fn();
            }, function () {
                // start
            }, function () {
                // end
            });
        }
    }



});